﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Jobs.TransformAccess
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using UnityEngine.Bindings;

#nullable disable
namespace UnityEngine.Jobs
{
  /// <summary>
  ///   <para>Position, rotation and scale of an object.</para>
  /// </summary>
  [NativeHeader("Runtime/Transform/ScriptBindings/TransformAccess.bindings.h")]
  public struct TransformAccess
  {
    private IntPtr hierarchy;
    private int index;
    private bool isReadOnly;

    /// <summary>
    ///   <para>The position of the transform in world space.</para>
    /// </summary>
    public Vector3 position
    {
      get
      {
        this.CheckHierarchyValid();
        Vector3 p;
        TransformAccess.GetPosition(ref this, out p);
        return p;
      }
      set
      {
        this.CheckHierarchyValid();
        this.CheckWriteAccess();
        TransformAccess.SetPosition(ref this, ref value);
      }
    }

    /// <summary>
    ///   <para>The rotation of the transform in world space stored as a Quaternion.</para>
    /// </summary>
    public Quaternion rotation
    {
      get
      {
        this.CheckHierarchyValid();
        Quaternion r;
        TransformAccess.GetRotation(ref this, out r);
        return r;
      }
      set
      {
        this.CheckHierarchyValid();
        this.CheckWriteAccess();
        TransformAccess.SetRotation(ref this, ref value);
      }
    }

    /// <summary>
    ///   <para>The position of the transform relative to the parent.</para>
    /// </summary>
    public Vector3 localPosition
    {
      get
      {
        this.CheckHierarchyValid();
        Vector3 p;
        TransformAccess.GetLocalPosition(ref this, out p);
        return p;
      }
      set
      {
        this.CheckHierarchyValid();
        this.CheckWriteAccess();
        TransformAccess.SetLocalPosition(ref this, ref value);
      }
    }

    /// <summary>
    ///   <para>The rotation of the transform relative to the parent transform's rotation.</para>
    /// </summary>
    public Quaternion localRotation
    {
      get
      {
        this.CheckHierarchyValid();
        Quaternion r;
        TransformAccess.GetLocalRotation(ref this, out r);
        return r;
      }
      set
      {
        this.CheckHierarchyValid();
        this.CheckWriteAccess();
        TransformAccess.SetLocalRotation(ref this, ref value);
      }
    }

    /// <summary>
    ///   <para>The scale of the transform relative to the parent.</para>
    /// </summary>
    public Vector3 localScale
    {
      get
      {
        this.CheckHierarchyValid();
        Vector3 r;
        TransformAccess.GetLocalScale(ref this, out r);
        return r;
      }
      set
      {
        this.CheckHierarchyValid();
        this.CheckWriteAccess();
        TransformAccess.SetLocalScale(ref this, ref value);
      }
    }

    /// <summary>
    ///   <para>Matrix that transforms a point from local space into world space (Read Only).</para>
    /// </summary>
    public Matrix4x4 localToWorldMatrix
    {
      get
      {
        this.CheckHierarchyValid();
        Matrix4x4 m;
        TransformAccess.GetLocalToWorldMatrix(ref this, out m);
        return m;
      }
    }

    /// <summary>
    ///   <para>Matrix that transforms a point from world space into local space (Read Only).</para>
    /// </summary>
    public Matrix4x4 worldToLocalMatrix
    {
      get
      {
        this.CheckHierarchyValid();
        Matrix4x4 m;
        TransformAccess.GetWorldToLocalMatrix(ref this, out m);
        return m;
      }
    }

    /// <summary>
    ///   <para>Use this to determine whether this instance refers to a valid Transform.</para>
    /// </summary>
    public bool isValid => this.hierarchy != IntPtr.Zero;

    /// <summary>
    ///   <para>Sets the world space position and rotation of the transform.</para>
    /// </summary>
    /// <param name="position"></param>
    /// <param name="rotation"></param>
    public void SetPositionAndRotation(Vector3 position, Quaternion rotation)
    {
      this.CheckHierarchyValid();
      TransformAccess.SetPositionAndRotation_Internal(ref this, ref position, ref rotation);
    }

    /// <summary>
    ///   <para>Sets the position and rotation of the transform in local space (that is, relative to its parent transform).</para>
    /// </summary>
    /// <param name="localPosition"></param>
    /// <param name="localRotation"></param>
    public void SetLocalPositionAndRotation(Vector3 localPosition, Quaternion localRotation)
    {
      this.CheckHierarchyValid();
      TransformAccess.SetLocalPositionAndRotation_Internal(ref this, ref localPosition, ref localRotation);
    }

    public void GetPositionAndRotation(out Vector3 position, out Quaternion rotation)
    {
      this.CheckHierarchyValid();
      TransformAccess.GetPositionAndRotation_Internal(ref this, out position, out rotation);
    }

    public void GetLocalPositionAndRotation(out Vector3 localPosition, out Quaternion localRotation)
    {
      this.CheckHierarchyValid();
      TransformAccess.GetLocalPositionAndRotation_Internal(ref this, out localPosition, out localRotation);
    }

    [NativeMethod(Name = "TransformAccessBindings::SetPositionAndRotation", IsThreadSafe = true, IsFreeFunction = true, ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void SetPositionAndRotation_Internal(
      ref TransformAccess access,
      ref Vector3 position,
      ref Quaternion rotation);

    [NativeMethod(Name = "TransformAccessBindings::SetLocalPositionAndRotation", IsThreadSafe = true, IsFreeFunction = true, ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void SetLocalPositionAndRotation_Internal(
      ref TransformAccess access,
      ref Vector3 localPosition,
      ref Quaternion localRotation);

    [NativeMethod(Name = "TransformAccessBindings::GetPositionAndRotation", IsThreadSafe = true, IsFreeFunction = true, ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void GetPositionAndRotation_Internal(
      ref TransformAccess access,
      out Vector3 position,
      out Quaternion rotation);

    [NativeMethod(Name = "TransformAccessBindings::GetLocalPositionAndRotation", IsThreadSafe = true, IsFreeFunction = true, ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void GetLocalPositionAndRotation_Internal(
      ref TransformAccess access,
      out Vector3 localPosition,
      out Quaternion localRotation);

    [NativeMethod(Name = "TransformAccessBindings::GetPosition", IsThreadSafe = true, IsFreeFunction = true, ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void GetPosition(ref TransformAccess access, out Vector3 p);

    [NativeMethod(Name = "TransformAccessBindings::SetPosition", IsThreadSafe = true, IsFreeFunction = true, ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void SetPosition(ref TransformAccess access, ref Vector3 p);

    [NativeMethod(Name = "TransformAccessBindings::GetRotation", IsThreadSafe = true, IsFreeFunction = true, ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void GetRotation(ref TransformAccess access, out Quaternion r);

    [NativeMethod(Name = "TransformAccessBindings::SetRotation", IsThreadSafe = true, IsFreeFunction = true, ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void SetRotation(ref TransformAccess access, ref Quaternion r);

    [NativeMethod(Name = "TransformAccessBindings::GetLocalPosition", IsThreadSafe = true, IsFreeFunction = true, ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void GetLocalPosition(ref TransformAccess access, out Vector3 p);

    [NativeMethod(Name = "TransformAccessBindings::SetLocalPosition", IsThreadSafe = true, IsFreeFunction = true, ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void SetLocalPosition(ref TransformAccess access, ref Vector3 p);

    [NativeMethod(Name = "TransformAccessBindings::GetLocalRotation", IsThreadSafe = true, IsFreeFunction = true, ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void GetLocalRotation(ref TransformAccess access, out Quaternion r);

    [NativeMethod(Name = "TransformAccessBindings::SetLocalRotation", IsThreadSafe = true, IsFreeFunction = true, ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void SetLocalRotation(ref TransformAccess access, ref Quaternion r);

    [NativeMethod(Name = "TransformAccessBindings::GetLocalScale", IsThreadSafe = true, IsFreeFunction = true, ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void GetLocalScale(ref TransformAccess access, out Vector3 r);

    [NativeMethod(Name = "TransformAccessBindings::SetLocalScale", IsThreadSafe = true, IsFreeFunction = true, ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void SetLocalScale(ref TransformAccess access, ref Vector3 r);

    [NativeMethod(Name = "TransformAccessBindings::GetLocalToWorldMatrix", IsThreadSafe = true, IsFreeFunction = true, ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void GetLocalToWorldMatrix(ref TransformAccess access, out Matrix4x4 m);

    [NativeMethod(Name = "TransformAccessBindings::GetWorldToLocalMatrix", IsThreadSafe = true, IsFreeFunction = true, ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void GetWorldToLocalMatrix(ref TransformAccess access, out Matrix4x4 m);

    [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
    [MethodImpl((MethodImplOptions) 256)]
    internal void CheckHierarchyValid()
    {
      if (!this.isValid)
        throw new NullReferenceException("The TransformAccess is not valid and points to an invalid hierarchy");
    }

    [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
    [MethodImpl((MethodImplOptions) 256)]
    internal void MarkReadWrite() => this.isReadOnly = false;

    [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
    [MethodImpl((MethodImplOptions) 256)]
    internal void MarkReadOnly() => this.isReadOnly = true;

    [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
    [MethodImpl((MethodImplOptions) 256)]
    private void CheckWriteAccess()
    {
      if (this.isReadOnly)
        throw new InvalidOperationException("Cannot write to TransformAccess since the transform job was scheduled as read-only");
    }
  }
}
